﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading.Tasks;

namespace homework3_file
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private OpClass op;
        public MainWindow()
        {
            InitializeComponent();
            op = new OpClass();
        }

        //选择文件
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            filePath.Text = op.selectCsharpFile();
        }

        //统计行数和单词数
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            int[] beforeCount = op.analyzeFile();
            if (beforeCount != null)
            {
                beforeLineCount.Content = "原始行数：" + beforeCount[0];
                beforeWordCount.Content = "原始单词数：" + beforeCount[1];
            }
        }

        //删除空行和注释
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            int[] afterCount = op.copCsharpFile();
            if (afterCount != null)
            {
                afterLineCount.Content = "格式化行数：" + afterCount[0];
                afterWordCount.Content = "格式化单词数：" + afterCount[1];
            }
        }

        //展示单词列表
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            List<WordCount> wordList = op.getWordsList();
            if (wordList != null)
            {
                wordListView.ItemsSource = wordList;
            }
        }
    }


}
